package com.example.glidewithsvg

import android.graphics.drawable.PictureDrawable
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import java.io.File

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_main)
        val imageView = findViewById<ImageView>(R.id.img_view)
        val btn_test = findViewById<Button>(R.id.btn_test)

        val svgPath = "SVG:false:/data/file/test.svg"

        Glide.with(this).`as`(PictureDrawable::class.java)
            .load(svgPath.toByteArray())
            .transition(DrawableTransitionOptions.withCrossFade())
            .into(imageView)

        btn_test.setOnClickListener {
            val svgPath = "SVG:true:/data/file/test.svg"
            Glide.with(this).`as`(PictureDrawable::class.java)
                .load(svgPath.toByteArray())
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(imageView)
        }
    }
}